<template>
  <div class="app-container">
    <!-- <el-dialog :title="isEditing?'修改':'添加'" :visible.sync="dialogFormVisible"> -->
    <el-form
      class="dialog-form"
      :rules="rules"
      ref="dataForm"
      :model="temp"
      label-position="left"
      label-width="120px"
    >
      <el-form-item label="栏目名称" prop="categoryName">
        <el-input v-model="temp.categoryName" placeholder="栏目名称" style="width:300px;"></el-input>
      </el-form-item>

      <el-form-item label="分类标识" prop="categoryNo">
        <el-input v-model="temp.categoryNo" placeholder="分类标识" style="width:300px;"></el-input>
      </el-form-item>

      <el-form-item label="排序" prop="sort">
        <el-input-number v-model="temp.sort" placeholder="排序"></el-input-number>
      </el-form-item>

      <el-form-item label="状态" prop="status">
        <el-select v-model="temp.status" placeholder="请选择">
          <el-option v-for="(item,value) in typeFilter" :key="value" :label="item" :value="value"></el-option>
        </el-select>
      </el-form-item>

      <!-- <el-form-item label="所属栏目" prop="categoryId">
          <el-select v-model="temp.categoryId" placeholder="请选择">
            <el-option v-for="(item,value) in cmsList" :key="value" :label="item.categoryName" :value="item.id"></el-option>
          </el-select>
        </el-form-item>

         <el-form-item label="阅读数量" prop="viewNum">
          <el-input-number v-model="temp.viewNum" placeholder="阅读数量"></el-input-number>
        </el-form-item>

         <el-form-item label="收藏数量" prop="collectNum">
          <el-input-number v-model="temp.collectNum" placeholder="收藏数量"></el-input-number>
      </el-form-item>-->
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button size="mini" @click="dialogFormVisible = false">取消</el-button>
      <el-button type="primary" size="mini" :loading="submiting" @click="submitFormAction">确定</el-button>
    </div>
    <!-- </el-dialog> -->
  </div>
</template>

<script>
import "quill/dist/quill.core.css";
import "quill/dist/quill.snow.css";
import "quill/dist/quill.bubble.css";

import { quillEditor, Quill } from "vue-quill-editor";

let typeFilter = ["未审核", "已审核"];
export default {
  data() {
    return {
      container: false,
      checkStatusList: [
        {
          label: "下线",
          value: 0
        },
        {
          label: "上线",
          value: 1
        }
      ],
      total: 0,
      params: {
        pageNo: 1,
        pageSize: 20
      },
      cmsList: [],
      list: [],
      temp: {
        categoryName: "",
        status: "",
        sort: "",
        categoryNo: ""
      },
      editorOption: {
        placeholder: "在这里输入内容",
        modules: {}
      },

      typeFilter: typeFilter,
      rules: {
        categoryName: [
          {
            required: true,
            message: "栏目名称",
            trigger: "change",
            max: 50
          }
        ],
        categoryNo: [
          { required: true, message: "分类标识不能为空", trigger: "change" }
        ],
        status: [
          { required: true, message: "排序不能为空", trigger: "change" }
        ],
        sort: [{ required: true, message: "状态不能为空", trigger: "change" }]
      }
    };
  },
  components: {
    quillEditor
  },
  created() {
    this.loadData();
  },

  filters: {
    typeFilter(status) {
      return typeFilter[parseInt(status)];
    }
  },
  methods: {
    submitFormAction() {
      this.$refs["dataForm"].validate(valid => {
        if (valid) {
          this.submiting = true;
          const postData = Object.assign({}, this.temp);
          let url = "/admin/cms_category/add";
          if (this.isEditing) {
            url = "/admin/cms_category/modify";
          }
          this.$post(url, postData)
            .then(data => {
                this.loadData();
                this.$$notify("操作成功");
                this.dialogFormVisible = false;
                this.temp = {};
            })
            // .catch(err => {
            //   this.$error(err.msg);
            //   this.submiting = false;
            // });
          .finally(err => {
            this.$$notify('操作成功')
            console.log(err)
            this.submiting = false
          })
        }
      });
    }
  }
};
</script>
<style>
.el-table td,
.el-table th {
  padding: 1px 0;
}
.el-table {
  font-size: 12px;
}
.opencolor {
  color: red;
}
.openSearch {
  /* width: 100px; */
  margin-bottom: 10px;
  padding-bottom: 5px;
  /* border-bottom: 1px solid #ccc; */
}
</style>